#include "stdafx.h"
#include "MainMenu.h"

using namespace MomogenkyouSystem;
using namespace MomogenkyouContent;

#pragma warning (disable : 4244)

MomogenkyouHelper::Grid g_Grid;

MainMenuScreen::MainMenuScreen()
:	m_iPhase(0)
{
	m_ScreenName = "MainMenu Screen";
	std::vector<std::string>	_TextureNames;
	_TextureNames.push_back("Data/Screens/Background.png");
	_TextureNames.push_back("Data/Screens/Title_Vertical.png");
	m_ContentManager.LoadTextures(_TextureNames);

	m_pBackground		=	m_ContentManager.GetTexture("Data/Screens/Background.png");
	m_pTitleText		=	m_ContentManager.GetTexture("Data/Screens/Title_Vertical.png");

	m_fTransitionOnTime	=	1.0f;
	m_fTransitionOffTime=	1.0f;

	m_pCamera = new MomogenkyouHelper::CameraFPS();
}

MainMenuScreen::~MainMenuScreen()
{
	m_pTitleText = NULL;
	m_pBackground = NULL;
	m_ContentManager.ClearContents();

	delete m_pCamera;
	m_pCamera = NULL;
}

void	MainMenuScreen::Initialize()
{
	m_iPhase = 0;

	m_pCamera->CalculateOrthographic(800, 450, -1.0f, 1000.0f);
	m_pCamera->SetPositionLook(float4(0, 20, 30, 1), MomogenkyouHelper::FLOAT4_ZERO);

	MomogenkyouSystem::SoundSystem::PlayBGM("Data/Screens/Agarest - War Suit.mp3");
}

void	MainMenuScreen::Shutdown()
{

}

void	MainMenuScreen::Update(const float & fInterval)
{
	//UNREFERENCED_PARAMETER(fInterval);
	switch(m_iPhase)
	{
	case 0:
		//	First Section
		//	Select Options etc
		//	Once Selected Jump down ++
		break;

	case 1:
		//	Activate screen based on selection
		//	When done Jump down
		break;

	case 2:

		break;
	}

	m_pCamera->Update(fInterval);
}

void	MainMenuScreen::ProcessInput()
{
	if(InputSystem::KeyReleased(DIK_END))
		ScreenManager::AddScreen(Global::LoadingLogo());

	//if(InputSystem::KeyReleased(DIK_LEFT))
	//if(InputSystem::KeyReleased(DIK_RIGHT))
	//if(InputSystem::KeyReleased(DIK_Z))
	//if(InputSystem::KeyReleased(DIK_X))
}

void	MainMenuScreen::DrawGameScreen(const float & fInterval)
{
	m_pCamera->CalculateOrthographic(800, 450, -1.0f, 1000.0f);
	UNREFERENCED_PARAMETER(fInterval);

	float	_Alpha	=	1.0f - m_fTransitionPosition;
	float4	_Color0	=	MomogenkyouHelper::FLOAT4_ONE * _Alpha;
	float4	_Color1	=	float4(1, 1, 1, _Alpha);

	//	Blend format
	GraphicsSystem::Device->SetRenderState(D3DRS_SRCBLEND,	D3DBLEND_SRCALPHA);
	GraphicsSystem::Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	//	2D
	/*GraphicsSystem::Device->SetTransform(D3DTS_VIEW, &MomogenkyouHelper::MATRIX_IDENTITY);
	GraphicsSystem::Device->SetTransform(D3DTS_PROJECTION, m_pCamera->ProjectionMatrix());*/

	//	Layer Background, may render in 3D
	{
		//	Background Image
		GraphicsSystem::Device->SetTexture(0, m_pBackground->Handle);
		Quad::RenderQuad(	m_pBackground->WidthHeight(), 
							MomogenkyouHelper::FLOAT4_ZERO, _Color0,	0);

		//	Title Text
		GraphicsSystem::Device->SetTexture(0, m_pTitleText->Handle);
		Quad::RenderQuad(	m_pTitleText->WidthHeight() * 0.75f, 
							float4(350, 0, 0, 1), _Color0,	0);

		//	Flower
		//	Petals
		//	Smoke
	}
	
	//	Layer Middle
	{
		//	Scroll Paper, Scroll Pole
	}

	//	Layer Buttons
	{
		

	}
	GraphicsSystem::Device->SetTexture(0, NULL);
	m_pCamera->CalculatePerspective(PIHALF * 0.5f, 1.77778f, 1.0f, 1000.0f);
	m_pCamera->CalculateView();
	g_Grid.Render();
}